/* Otakuslide
 * By: Andrew Bailey
 * Project Originated in 2010
 * 
 * Port # 16256
 * 
 */
import java.awt.*;
import java.awt.event.*;
import java.awt.image.BufferStrategy;

public class Game extends Frame implements Manager, KeyListener, MouseListener, MouseMotionListener {
	
	private Sequence current;
	
	private long cycleduration;
	private long precycle, postcycle;
	
	private String name;
	
	private BufferStrategy strategy;
	private int width, depth;
	
	private boolean delay;
	private int threads;
	
	private Player user;
	private Player[] p;
	
	public Game() {
		hardcode();
		this.setTitle(name);
		this.setVisible(true);
		this.requestFocus();
		this.setBackground(Color.WHITE);
		this.setBounds(0,0,width + this.getInsets().left + this.getInsets().right, depth + this.getInsets().top + this.getInsets().bottom);
		this.addWindowListener (new WindowAdapter()
		{
			public void windowClosing (WindowEvent e)
			{
				endProgram();
			}
		});
		this.createBufferStrategy(2);
		strategy = this.getBufferStrategy();
		this.addKeyListener(this);
		this.addMouseListener(this);
		this.addMouseMotionListener(this);
	}

	public void hardcode() {
		name = "Otakuslide";
		
		width = 760; // Maximum width for Facebook.com application.
		depth = 570; // Maximum height for Facebook.com application.
		
		threads = 0;
		delay = true;
		current = new IntroductionSequence(this);
	}

	public void run() {
		precycle = System.nanoTime();
		while(true)
		{
			update();
			manage();
		}
	}

	public void update() {
		if(current != null)
		{
			current.update();
		}
	}

	public void display() {
		Graphics g = strategy.getDrawGraphics();
		
		strategy.show();
	}

	public void manage() {
		postcycle = System.nanoTime();
		cycleduration = postcycle - precycle;
		precycle = postcycle + 0;
	}
	
	public synchronized void addUpdate() {
		
	}
	public synchronized void setDelay(boolean sd){delay = sd;}
	public boolean getDelay(){return delay;}
	public synchronized void increment(){threads++;}
	public synchronized void decrement(){threads--;}
	public Sequence getCurrentSequence(){
		return current;
	}
	public void setCurrentSequence(Sequence s){
		Sequence temp = s;
		current = temp;
	}
	
	public void endProgram() {
		this.setVisible(false);
		System.exit(0);
	}
	
	public void keyPressed(KeyEvent e){}
	public void keyReleased(KeyEvent e){}
	public void keyTyped(KeyEvent e){}
	public void mousePressed(MouseEvent e){}
	public void mouseClicked(MouseEvent e){}
	public void mouseReleased(MouseEvent e){}
	public void mouseEntered(MouseEvent e){}
	public void mouseExited(MouseEvent e){}
	public void mouseMoved(MouseEvent e){}
	public void mouseDragged(MouseEvent e){}
	
	public static void main (String [] args) {
		Game exe = new Game();
		exe.run();
	}
}
